﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

namespace MainWebService
{
    
    public class UserDetails
    {
        public List<ServiceDetails> Services { get; set; }
        public string UserName { get; set; }
        private string _password;

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string PhoneNumber { get; set; }
        
        public string HashCode { get; set; }

        
        public string Password { set { _password = value; } get { return _password; } }

        
        public string Company { get; set; }

        
        public UserAccessDetails UserAccess { get; set; }

        
        public string EmailId { get; set; }

        
        public string LastLogin { get; set; }

        private bool _isValidated;
        
        public bool IsUserValidated { get { return _isValidated; } set { _isValidated = value; } }

        
        public string CreateDate { get; set; }

        
        public string LoginMessage { get; set; }

        
        public int DeviceLimit { get; set; }

        
        public List<string> ServiceList { get; set; }

        
        public DataSet GetServiceList { get; set; }

        
        public int ClientId { get; set; }

        public int RoleId { get; set; }

        public DateTime AccountExpiry { get; set; }

        public string TimeZone { get; set; }
        public UserDetails()
        {

        }

        public UserDetails ValidateUser(string deviceId,string deviceName)
        {
            UserOperations _uOps = new UserOperations();
            UserDetails _usr = _uOps.ValidateUser(UserName, _password,deviceId,deviceName);
            return _usr;
        }
        
        public string AddUser()
        {
            UserOperations _usr = new UserOperations();
            return _usr.AddUser(UserId,EmailId, UserName, _password, Company,DeviceLimit,ClientId,ServiceList,HashCode);
        }
       
        
        public int UserId { get; set; }

        internal string DeleteUser()
        {

            UserOperations _usr = new UserOperations();
            return _usr.DeleteUser(UserId, ClientId,HashCode);
        }

        internal string UpdateUser()
        {
            UserOperations _usr = new UserOperations();
            return _usr.UpdateUser(UserId,UserName, _password,DeviceLimit, ClientId, ServiceList,HashCode);
        }

        internal static List<UserDetails> GetUserList(int clientId, string HashCode)
        {
            UserOperations _usr = new UserOperations();
            return _usr.ListUsers(clientId, HashCode);
        }

        internal static UserDetails ListAppUser(int userId, int clientId, string hashCode)
        {
            UserOperations _usr = new UserOperations();
            return _usr.ListUser(userId, clientId, hashCode);
        }

        internal static DataSet GetUsers(int userId, string hashCode)
        {
            return new UserOperations().GetUsers(userId, hashCode);
        }

        internal static void AssociateService(int UserId, string HashCode, int ServiceId, string usersList)
        {
             new UserOperations().AssociateService(UserId, HashCode, ServiceId, usersList);
        }

        internal static DataSet GetServicesList(int clientId, string hashCode)
        {
            return new UserOperations().GetServicesList(clientId, hashCode);
        }

        internal static DataSet GetAppUsers(int clientId, string hashCode)
        {
            return new UserOperations().GetUsersList(clientId, hashCode);
        }
        internal static DataSet GetDevices(int clientId, string hashCode)
        {
            return new UserOperations().GetDevicesList(clientId, hashCode);
        }

        internal static string Activate(int userId, string hash)
        {
            return new UserOperations().ActivateUser(userId, hash);
        }

        internal static string GetUserSecurity(string email, string type)
        {
            return new UserOperations().GetSecurity(email, type);
        }

        internal static string GetEmail(string token)
        {
            return new UserOperations().GetEmail(token);
        }

        internal static string ResetPassword(string token, string newPassword)
        {
            return new UserOperations().ResetPassword(token, newPassword);
        }

        internal static DataSet GetAccountUsers(string userId)
        {
            int uid = 0;
            Int32.TryParse(userId, out uid);             
            return new UserOperations().GetAccountUsers(uid);
        }
    }

    
    public class UserAccessDetails
    {
        public List<string> Databases { get; set; }
        public List<string> Services { get; set; }
    }
}